package com.example.demo.practice.enterprise;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.example.demo.practice.R;
import com.example.demo.practice.tool.ServerHttp;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Enterprise extends AppCompatActivity {
    private  ServerHttp serverHttp;
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            JSONArray jsonArray=serverHttp.getData();
            Log.e("ss", String.valueOf(jsonArray));
            TextView area= (TextView) findViewById(R.id.area);
            TextView status= (TextView) findViewById(R.id.status);
            TextView controller= (TextView) findViewById(R.id.controller);
            TextView phone= (TextView) findViewById(R.id.phone);
            TextView address= (TextView) findViewById(R.id.address);
            TextView introduce= (TextView) findViewById(R.id.introduce);
            try {
                JSONObject jsonObject= (JSONObject) jsonArray.get(0);
                area.setText(jsonObject.getString("admregion"));
                status.setText(jsonObject.getString("aduitstatu"));
                controller.setText(jsonObject.getString("controller"));
                phone.setText(jsonObject.getString("phnnumber"));
                introduce.setText(jsonObject.getString("introdece"));
                address.setText(jsonObject.getString("address"));
            } catch (JSONException e) {
                e.printStackTrace();
            }

            super.handleMessage(msg);
            serverHttp.clear();
            serverHttp=null;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_enterprise);
        Intent intent=getIntent();
        String title=intent.getStringExtra("name");
        setTitle(title);

        serverHttp=new ServerHttp(handler);
        serverHttp.setUrl("enterpriseByName?name="+title);
    }
}
